#!/bin/bash
# /**
# * Copyright (c) 2018, God's harbor
# * All rights reserved.
# * @file    burn_openert.sh
# * @brief   将image文件烧录到SD卡上
# * @author  Jason Zhou,yzfcer@163.com
# * @version 1.0
# * @date    2021-09-15
# */

usage()
{
    echo "usage:"
    echo "burn_openert.sh <img_gz_file> <disk>"
}

main()
{
    if [ $# -lt 2 ]
    then
        usage
        exit
    fi

    file=$1
    disk=$2
    if [ ! -f $file ]
    then
        echo "miss $file, maybe is not exist"
        usage
        exit
    fi

    if [ ! -b $disk ]
    then
        echo "miss $disk, maybe is not exist"
        usage
        exit
    fi
    zcat $file | sudo dd of=${disk} bs=512K iflag=fullblock conv=fsync status=progress
}

main $@
